<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/6/15
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body style="background-color:#7fecba">
<br>
<br>
<br>
<form class="layui-form layui-row layui-col-space16 ">
    <div class="layui-col-md4 ">
        <div class="layui-input-wrap">
            <input type="text" name="address" value="" placeholder="地址" class="layui-input" lay-affix="clear">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <input type="text" name="house_type" placeholder="户型" lay-affix="clear" class="layui-input">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-form-item layui-inline">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" id="date1" class="layui-input" name="post_date" autocomplete="off"
                       placeholder="发布日期">
            </div>
        </div>

    </div>
    <div class="layui-btn-container layui-col-xs12">
        <button style="margin-left: 10px" class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
        <button type="reset" class="layui-btn layui-btn-primary">清空</button>
    </div>
</form>
<table class="layui-hide" id="ID-table-demo-search" lay-filter="test"></table>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="/layui/layui.js"></script>
<script>
    function show_img(t) {
        var $ = layui.$;
        var layer = layui.layer;
        var t = $(t).find("img");
        //页面层
        layer.open({
            type: 1,
            title: '户型图',
            skin: 'layui-layer-rim', //加上边框
            area: ['80%', '80%'], //宽高 t.width() t.height()
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
        });
    }

    layui.use(function () {
        var $ = layui.$;
        var util = layui.util;
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({elem: "#date1", range: "~", trigger: 'click'});

        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/housefindall', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {
                    field: 'house_type_diagram', width: 80, title: '户型图', templet: function (d) {
                        return '<div onclick="show_img(this)" ><img src="' + d.house_type_diagram + '" ' + 'alt="" width="50px" height="50px"></a></div>';
                    }
                },
                {field: 'house_type', title: '户型', width: 100},
                {field: 'build_area', title: '建筑面积', sort: true, width: 120,},
                {field: 'inside_area', title: '套内面积', sort: true, width: 120},
                {field: 'address', title: '地址'},
                {field: 'price', title: '估计价格', sort: true, width: 150,},
                {
                    width: 180, field: 'post_date', title: '发布日期', sort: true, templet: function (d) {
                        return util.toDateString(d.post_date * 1000, "yyyy-MM-dd HH:mm:ss")
                    }
                }, {field: 'purchase_date', title: '购买日期', sort: true, width: 180,}
            ]],
            page: true,
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function (data) {
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                url: '/findhouse',
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            return false; // 阻止默认 form 跳转
        });

    });


</script>

</body>
</html>